package 原型模式.邮件;

public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        Attachment attachment = new Attachment();
        Email email = new Email(attachment, "邮件1", 1);

        System.out.println("--------------------------浅克隆方式----------------------------------------");
        Email email1 = (Email) email.clone();
        System.out.println("本体的hashcode:"+email.hashCode()+"\t对象属性:"+email.toString());
        System.out.println("克隆1号的hashcode:"+email1.hashCode()+"\t对象属性"+email1.toString());

        System.out.println();
        System.out.println("--------------------------使用二次拷贝的深克隆方式----------------------------------------");
        Email email2 = (Email) email.deepClone();
        System.out.println("本体的hashcode:"+email.hashCode()+"\t对象属性:"+email.toString());
        System.out.println("克隆1号的hashcode:"+email2.hashCode()+"\t对象属性"+email2.toString());


        /**
         * 由此可以看出，使用浅拷贝和深拷贝，成员属性邮件标题，邮件等级值都是相同的
         * 因为深拷贝底层也是用了浅拷贝，只不过调用了成员对象引用的再次拷贝而已。
         */
    }
}
